package com.xuyiwei.mayi;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * Created by xuyiwei on 2019/4/16.
 */
public class SessionDemo extends HttpServlet {
    private int i = 1;

    public SessionDemo() {
        System.out.println("servlet构造方法");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("获取session开始");
        HttpSession session = req.getSession();
        System.out.println(session);
        System.out.println("获取session借宿");
        req.getRequestDispatcher("/servletdemo/index.jsp").forward(req, resp);
    }

    @Override
    public void destroy() {
        System.out.println("servlet已经被销毁");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("servlet的init方法");
    }
}
